﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_Contact_ContactMain : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Alert1.HideMessage();
        if (!IsPostBack)
        {
            BindData(1);
        }
    }

  

    #region Paging & Message
 
    #endregion

    #region DataProcessing
    private void BindData(int CurrentPageIndex)
    {
        int nPageCount = 0;
        int nStatus = -1;
        int nDefLang = Support.GetDefaultLanguage();
        Contacts objContactUs = new Contacts();
        DataTable dtbContactUs = new DataTable();
        dtbContactUs = objContactUs.Search(0, nStatus, CurrentPageIndex, Config.PAGESIZE, ref nPageCount);
        RpContact.DataSource = dtbContactUs;
        RpContact.DataBind();
        lblTotalRecord.Text = MultipleLanguage.LBL_TOTAL_ITEM[nDefLang - 1] + nPageCount + MultipleLanguage.LBL_FOUND[nDefLang - 1];
       
    }

    protected void RpLink_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);
        Contacts objContactUs = new Contacts();
        switch (strCommand)
        {
            case "Delete":
                int nDelete = objContactUs.DeleteById(nID);
                //if (nDelete > 0)
                //    Alert1.ShowMessage(1, MessagesAlert.DELETE_SUCCESSFULL[nDefaultLanguage ]);
                //else
                //    Alert1.ShowMessage(2, MessagesAlert.DELETE_UNSUCCESSFULL[nDefaultLanguage ]);
                BindData(1);
                break;

            case "Edit":
                string sEdit = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_CONTACT_ADD + "&" + Config.ACTION + "=" + Config.ACTION_EDIT + "&" + Config.ACTION_ID + "=" + nID;
                Response.Redirect(sEdit);
                break;
        }
    }
    protected void RpLink_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nDefaultLanguage = Support.GetDefaultLanguage() - 1;
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label lblFullName = (Label)e.Item.FindControl("lblFullName");
            Label lblTelephone = (Label)e.Item.FindControl("lblTelephone");
            Label lblEmail = (Label)e.Item.FindControl("lblEmail");
            Label lblDatePosted = (Label)e.Item.FindControl("lblDatePosted");


            Label lnkUnread = (Label)e.Item.FindControl("lnkUnread");
            Label lnkRead = (Label)e.Item.FindControl("lnkRead");
            LinkButton lnkEdit = (LinkButton)e.Item.FindControl("lnkEdit");
            LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");

            lblEmail.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Email"));
            
            lblFullName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "FullName")); ;
            lblDatePosted.Text = ConvertData.ConvertIntToDatetimeString(ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "CreatedDate")));

            int nStatus = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "Status"));
            if (nStatus > 0)
            {
                // read
                lnkUnread.Visible = false;
                lnkRead.Visible = true;
            }
            else
            {
                lnkUnread.Visible = true;
                lnkRead.Visible = false;
            }


            lnkEdit.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ContactID"));
            lnkDelete.OnClientClick = Support.CreateConfirmBoxClient(MessagesAlert.DELETE_ALERT[nDefaultLanguage]);
            lnkDelete.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ContactID"));
        }
    }
}
    #endregion

